package com.Day11.TreeSet;

/**
 * @author: 若若叶
 * @date: 2021/7/19 12:51
 * FileName: User
 * Description: 用户
 */
public class User implements Comparable<User>{
    private String username;
    private Integer age;

    public User() {
    }

    public User(String username, Integer age) {
        this.username = username;
        this.age = age;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "username='" + username + '\'' +
                ", age=" + age +
                '}';
    }

    /**
     * 重新比较方法
     * @param o  被比较的User对象
     * @return  按照年龄从小到大，年龄一样，按名字从小到大
     */
    @Override
    public int compareTo(User o) {
        if (this.age == o.age){
            return this.username.compareTo(o.username);
        }
        return this.age-o.age;
    }
}
